<template>
	<view>
		<view class="zhaobiao-header">
			<view class="zhaobiao-header-content">
				<view class="zhaobiao-tag">
					<text v-show="type == 2">业主</text>
					<text v-show="type == 5">供应商</text>
					<text v-show="type == 1">代理</text>
				</view>
				<view class="zhaobiao-yezhu-text">
					<view class="yezhu-name text-ellipsis">{{company}}</view>
					<view class="yezhu-gz">{{gzcount}}人正在监控该公司</view>
				</view>
				<view class="guanzhu-btn" :class="!isguanzhu ? 'weiguanzhu' :''"  @click="clickGuanzhu">{{isguanzhu ? '已关注':'关注'}}</view>
			</view>
			<view class="zhaobiao-warpper">
				<view class="zhaobiao-title">相关
				<text v-show="type == 2">招标</text><text v-show="type == 5">中标</text><text v-show="type == 1">代理招标</text>
				
				项目（{{count}}条）</view>

				<view class="uni-list" v-if="newsList.length">
					<view v-for="(item, index) in newsList" :key="index" class="news-item" @click="navToDetails(item)">
						<view class="news-media-list">
							<view class="title">
								{{item.title}}
							</view>
							<view class="infor">
								{{item.contentText}}
							</view>
							<view class="bot">
								<view class="bot-text author">
									<image class="type-icon" src="/static/img/home/zb-icon.png"></image>{{item.typeStr}}
								</view>
								<view class="bot-text area">
									<image class="type-icon" src="/static/img/home/diqu-icon.png"></image>{{item.diqu}}
								</view>
								<view class="bot-text time red">
									<image class="type-icon" src="/static/img/home/time-icon.png"></image>{{item.time}}
								</view>
								<!-- 附件 -->
								<view class="bot-text file" v-if="item.fujian==2">
									<image class="type-icon" src="/static/img/home/fujian.png"></image>附件
								</view>
								<!-- 标书 -->
								<view class="bot-text biaoshu" v-if="item.fujian==1">
									<image class="type-icon" src="/static/img/biaoshu.png"></image> 标书
								</view>
							</view>

						</view>
					</view>
				</view>
				
				<view class="nullWrap" v-else-if="!newsList.length && status === 'noMore'">
					<image src="https://img.bidcenter.com.cn/uni/zanwushuju.png" mode="aspectFit"
						>
					</image>
				</view>
				
				<!-- 上滑加载更多组件 -->
				<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
			</view>
		</view>
		<view class="foot-qyxq"  @click="toQiqing" v-if="!baseConfig.isIOSshenhe" >
			<u-loading-icon color="#fff" style="margin-top: 20rpx;" v-if="status=='loading'"></u-loading-icon>
			<text v-else>企业分析</text>
		</view>

	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				newsList: [],
				status: 'more',
				pagesize: 20,
				pageindex: 1,
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				company: '',
				guanzhutype: 2,
				nexttoken: '',
				gzcount: 0,
				count: 0,
				type:'',
				isguanzhu:true,
				comcode:'',
				vcode:''
			};
		},
		onLoad(options) {
			
			if (options.comname != '' && options.comname != undefined) {
				this.company = decodeURIComponent(options.comname);
			}
			this.type = options.type
			this.getList("add");
		},
		onPullDownRefresh() {
			this.getList("refresh");
		},
		onReachBottom() {
			this.getList("add");
		},
		onUnload() {
			uni.hideNavigationBarLoading(); //关闭加载动画
		},
		methods: {
			getList(type) {
				//type add 加载更多 refresh下拉刷新
				if (type === 'add') {
					if (this.status === "noMore") {
						return;
					}
					this.status = "loading";
				}
				if (type === 'refresh') {
					this.status = 'more';
					uni.showNavigationBarLoading();
					this.pageindex = "1";
					uni.pageScrollTo({
						scrollTop: 0,
						duration: 100
					});
				}
				let data = this.initNewData();
				data.from = 4038;
				data.location = 5230;
				data.company = encodeURIComponent(this.company);
				data.guanzhutype = this.type;
				data.pagesize = this.pagesize;
				data.page = this.pageindex;
				data.nexttoken = this.nexttoken;
				
				data.backvcode = 1 //默认0：否；1：是
				uni.request({
					url: this.baseConfig.serverURL + 'user/guanzhu/GuanzhuDetailHandler.ashx',
					data: data,
					method: "POST",
					header: {
						"content-type": "application/x-www-form-urlencoded" //"application/json"
					},
					success: (res) => {
						uni.hideToast();
						if (res.statusCode == 200) {
							if (!res.data.ret) {
								uni.showToast({
									title: res.data.msg,
									icon: "none"
								});
								this.status = "noMore";
								uni.stopPullDownRefresh();
								uni.hideNavigationBarLoading(); //关闭加载动画
								return;
							} else {
								//数据放前面，否则list为空 会走下面的return
								this.count = res.data.other2.count;
								this.gzcount = res.data.other2.gzcount;
								this.comcode = res.data.other2.comcode
								this.vcode = res.data.other2.vcode
								//获取成功，绑定
								let list = res.data.other2.list;
								if (list == undefined || list == '' || list.length <= 0) {
									//console.log("没数据了");
									this.status = "noMore";
									uni.stopPullDownRefresh();
									uni.hideNavigationBarLoading(); //关闭加载动画
									return;
								}
								this.nexttoken = res.data.other2.nexttoken;
								if (type === 'refresh') {
									console.log("下拉刷新");
									this.newsList = []; //刷新前清空数组
								}
								list.forEach(item => {
									item.time = item.time.split('T')[0];
									this.newsList.push(item);
								})

								this.status = "more";
								if (list.length < this.pagesize) {
									this.status = "noMore";
								}
								this.pageindex++;
								
								
								uni.stopPullDownRefresh(); //得到数据后停止下拉刷新
								uni.hideNavigationBarLoading();
							}
						} else {
							uni.showToast({
								title: '获取信息失败',
								icon: "none"
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							title: '获取信息失败！',
							icon: "none"
						});
					}
				});
			},
			navToDetails(item) {
				let uri = encodeURIComponent(JSON.stringify(item));
				switch (item.type) {
					case 3:
					case 10:
					case 11:
					case 12:
					case 13:
					case 14:
					case 98:
					case 99:
						uni.navigateTo({
							url: '/pages/xiangmu/detail?ly=guanzhu&data=' + encodeURIComponent(uri)
						})
						break;
					default:
						uni.navigateTo({
							url: '/pages/zhaobiao/detail?ly=guanzhu&data=' + encodeURIComponent(uri)
						})
						break;
				}
			},
			clickGuanzhu(){
				uni.$u.http
					.post('user/guanzhu/GuanzhuHandler.ashx', {
						location: 10870,
						comname:this.company,
						type:this.type
					})
					.then(rs => {
						if(rs.type == 1){
							this.isguanzhu = false
							uni.$u.toast('已取消关注');
						}else{
							this.isguanzhu = true
							uni.$u.toast('关注成功');
						}
						
					});
			},
			toQiqing(){
				if (this.baseConfig.isIOSshenhe || this.status=='loading') {
					return
				}
				uni.navigateTo({
					url:'/pages/qiqing/index?companyName=' + this.company + '&comcode=' + this.comcode + '&vcode=' + this.vcode + '&type=' + this.type
				})
			}

		}
	}
</script>

<style lang="scss">
	@import "@/static/css/commonList.scss";

	page {
		background-color: #fafafa;
	}
	// .news-item{
	// 	margin: 0 30rpx;
	// }

	.zhaobiao-header {
		height: 60rpx;
		background-color: #1B18F7;
	}

	.zhaobiao-header-content {
		display: flex;
		flex-direction: row;
		align-items: center;
		background-color: #fff;
		margin: 0 30rpx;
		padding: 12rpx 15rpx;
		border-radius: 4rpx;
		border: 1px solid #E9E9EB;

		.zhaobiao-tag {
			width: 86rpx;
			height: 86rpx;
			background: #E7F0FF;
			border-radius: 4rpx;
			font-size: 28rpx;
			color: #2F7FFF;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-right: 17rpx;
		}

		.zhaobiao-yezhu-text {
			flex: 1;
			overflow: hidden;

			.yezhu-name {
				font-size: 30rpx;
			}

			.yezhu-gz {
				color: #b6b6b6;
				font-size: 28rpx;
			}
			.text-ellipsis{
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}
		}
		.guanzhu-btn{
			height: 52rpx;
			padding: 0 15px;
			display: flex;
			align-items: center;
			justify-content: center;
			background: #D1D1D1;
			border-radius: 4rpx;
			font-size: 24rpx;
			color: #FFFFFF;
			&.weiguanzhu{
				background-color: #2F6DFE;
			}
		}
	}

	.zhaobiao-warpper {
		margin-top: 20rpx;
		padding-bottom: 98rpx;

		.zhaobiao-title {
			font-size: 30rpx;
			margin: 0 30rpx 20rpx;
		}
	}
	.uni-list .news-item{
		margin: 0 20rpx 20rpx;
		.bot{
			justify-content: inherit;
		}
		.bot-text{
			display: flex;
			align-items: center;
			margin-right: 10rpx;
		}
	}
	.foot-qyxq{
		height: 98rpx;
		line-height: 98rpx;
		text-align: center;
		background: #2F6DFE;
		font-weight: 800;
		font-size: 32rpx;
		color: #FFFFFF;
		position: fixed;
		width: 100%;
		bottom: 0;
		left: 0;
	}
	
	.nullWrap{
		display: flex;
		justify-content: center;
		margin-top: 50rpx;
	}
</style>
